# -*- coding: utf-8 -*-
#import time
import pygame
from . import config


def RoundDisplay(pencere, nround, frame):
    font = pygame.font.Font("font/BIRTH OF A HERO.ttf", frame * 10)
    disp = font.render(
        "Round " + str(nround),
        1,
        (152, 0, 0)
    )
    pencere.blit(
        disp,
        (
            (config.x / 2) - disp.get_rect().width / 2,
            (config.y / 2) - disp.get_rect().height
        )
    )


def WinDisplay(pencere, player):
    font = pygame.font.Font("font/BIRTH OF A HERO.ttf", 64)
    disp = font.render(
        "Winner",
        1,
        (152, 0, 0)
    )

    if player == 1:
        x = 10
    else:
        x = config.x - disp.get_rect().width - 10

    pencere.blit(
        disp,
        (
            x,
            (config.y / 2) - disp.get_rect().height
        )
    )


def WinnerScreen(pencere, winner_name):
    show = True
    saat = pygame.time.Clock()

    font = pygame.font.SysFont("None", 128)
    font2 = pygame.font.SysFont("None", 64)

    dps = font.render("WINNER", 1, (255, 255, 255))
    dps2 = font2.render(winner_name, 1, (255, 255, 255))

    y = (config.y / 2) - dps.get_rect().height
    y2 = (config.y / 2)
    x = -dps.get_rect().width

    i = 0
    while show:
        pencere.fill((0, 0, 0))
        pencere.blit(dps, (x, y))
        pencere.blit(dps2, (x, y2))
        if x < (config.x - dps.get_rect().width - 50):
            x += 50
        if i >= 60:
            show = False
        i += 1

        pygame.display.update()

        saat.tick(20)


def Splash(pencere):

    saat = pygame.time.Clock()
    delay = 41

    spl_font_big = pygame.font.SysFont("None", 128)
    spl_font = pygame.font.SysFont("None", 64)
    spl_font_small = pygame.font.SysFont("None", 16)

    splash, splash_all = True, True
    color_key = 0

    while splash and splash_all:

        #time.sleep(0.02)
        saat.tick(delay)
        pencere.fill((0, 0, 0))
        disp = spl_font_big.render(
            "PyFI",
            1,
            (color_key, color_key, color_key)
        )
        pencere.blit(
            disp,
            (
                (config.x / 2) - disp.get_rect().width / 2,
                (config.y / 2) - disp.get_rect().height
            )
        )
        disp2 = spl_font_small.render(
            "Python Figthers",
            1,
            (color_key, color_key, color_key)
        )
        pencere.blit(
            disp2,
            (
                (config.x / 2) + disp2.get_rect().width / 2,
                (config.y / 2) - disp2.get_rect().height
            )
        )
        color_key += 1
        #color_key_n -= 1
        if color_key >= 255:
            splash = False

        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_SPACE):
                    splash_all = False

        pygame.display.update()

    splash = True
    color_key = 0

    while splash and splash_all:

        #time.sleep(0.02)
        saat.tick(delay)
        pencere.fill((color_key, color_key, color_key))
        disp = spl_font_big.render(
            "PyFI",
            1,
            (255, 255, 255)
        )
        pencere.blit(
            disp,
            (
                (config.x / 2) - disp.get_rect().width / 2,
                (config.y / 2) - disp.get_rect().height
            )
        )
        disp2 = spl_font_small.render(
            "Python Figthers",
            1,
            (255, 255, 255)
        )
        pencere.blit(
            disp2,
            (
                (config.x / 2) + disp2.get_rect().width / 2,
                (config.y / 2) - disp2.get_rect().height
            )
        )
        color_key += 1
        #color_key_n -= 1
        if color_key >= 255:
            splash = False

        pygame.display.update()

    splash = True
    color_key = 255

    while splash and splash_all:

        #time.sleep(0.02)
        saat.tick(delay)
        pencere.fill((255, 255, 255))
        disp1 = spl_font.render(
            "and ROOT404",
            1,
            (color_key, color_key, color_key)
        )
        pencere.blit(
            disp1,
            (
                (config.x / 2) - disp1.get_rect().width,
                (config.y / 2) - disp1.get_rect().height
            )
        )

        dy = (config.y / 2) - disp.get_rect().height + disp1.get_rect().height

        disp = spl_font.render(
            "present",
            1,
            (color_key, color_key, color_key)
        )
        pencere.blit(
            disp,
            (
                (config.x / 2) - disp.get_rect().width / 2,
                dy
            )
        )
        color_key -= 1
        if color_key <= 75:
            splash = False

        pygame.display.update()

    splash = True
    color_key = 75

    while splash and splash_all:

        #time.sleep(0.02)
        saat.tick(delay)
        pencere.fill((255, 255, 255))

        disp1 = spl_font.render(
            "and ROOT404",
            1,
            (color_key, color_key, color_key)
        )
        pencere.blit(
            disp1,
            (
                (config.x / 2) - disp1.get_rect().width,
                (config.y / 2) - disp1.get_rect().height
            )
        )

        dy = (config.y / 2) - disp.get_rect().height + disp1.get_rect().height

        disp = spl_font.render(
            "present",
            1,
            (color_key, color_key, color_key)
        )
        pencere.blit(
            disp,
            (
                (config.x / 2) - disp.get_rect().width / 2,
                dy
            )
        )
        color_key += 1
        if color_key >= 255:
            splash = False

        pygame.display.update()

    splash = True
    color_key = 255

    while splash and splash_all:

        #time.sleep(0.02)
        saat.tick(delay)
        pencere.fill((color_key, color_key, color_key))

        disp = spl_font.render(
            "in asosciation",
            1,
            (255, 255, 255)
        )
        pencere.blit(
            disp,
            (
                (config.x) - disp.get_rect().width - 20,
                (config.y / 2) - disp.get_rect().height
            )
        )

        disp2 = spl_font.render(
            "with BURRITOS TIA SANTA",
            1,
            (255, 255, 255)
        )
        pencere.blit(
            disp2,
            (
                (config.x) - disp2.get_rect().width - 20,
                (config.y / 2)
            )
        )

        color_key -= 1
        if color_key <= 0:
            splash = False

        pygame.display.update()